package com.talos.framework.common.util.string;

import java.util.Random;

public class RamdonStringUtils {

	// 产生一个随机数 方法1
	public static String getRandomString(int length) {
		String str = "abcdefghigklmnopkrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ0123456789";
		Random random = new Random();
		StringBuffer sf = new StringBuffer();
		for (int i = 0; i < length; i++) {
			int number = random.nextInt(62);// 0~61
			sf.append(str.charAt(number));

		}
		return sf.toString();
	}

	// 产生一个随机数 方法2
	public static String getRandomString2(int length) {
		Random random = new Random();
		StringBuffer sf = new StringBuffer();
		for (int i = 0; i < length; i++) {
			int number = random.nextInt(3);
			long result = 0;
			switch (number) {
			case 0:
				result = Math.round(Math.random() * 25 + 65);
				sf.append(String.valueOf((char) result));
				break;

			case 1:
				result = Math.round(Math.random() * 25 + 97);
				sf.append(String.valueOf((char) result));
				break;
			case 2:
				sf.append(String.valueOf(new Random().nextInt(10)));
				break;
			}
		}
		return sf.toString();
	}
	
	 
    public static int getRamdonInt(int min,int max){
    	return (int) ((max - min + 1) * Math.random() + min);
    }
    
    public static String getRamdonIntStr(int length){
    	String str = "0123456789";
		Random random = new Random();
		StringBuffer sf = new StringBuffer();
		for (int i = 0; i < length; i++) {
			int number = random.nextInt(10);// 0~61
			sf.append(str.charAt(number));

		}
		return sf.toString();
    }
    
    public static String getRamdonString4to20(){
    	return getRandomString(getRamdonInt(4,20));
    }
    
    public static String getRamdonStrRange(int min, int max){
    	return getRandomString(getRamdonInt(min,max));
    }


	public static void main(String args[]) {
		System.out.println(getRamdonIntStr(6));
		//System.out.println(getRandomString2(10));
	}

}
